class CreateScheduledRecords < ActiveRecord::Migration
  def self.up
    create_table :scheduled_records do |t|
      t.integer :fromDate
      t.integer :toDate

      t.integer :generatedFrom
      t.integer :generatedTo

      t.string :cron
      t.string :tweetJson

      t.references :wallet
    end

    add_index :scheduled_records, :fromDate
    add_index :scheduled_records, :toDate

    add_index :scheduled_records, :generatedFrom
    add_index :scheduled_records, :generatedTo

    add_index :scheduled_records, :wallet_id

    create_table :operations_scheduled_records, :id => false  do |t|
      t.integer :operation_id
      t.integer :scheduled_record_id
    end

    add_index :operations_scheduled_records, [:operation_id, :scheduled_record_id], :name => 'index_operations_scheduled_records', :unique => true

    #  1 - approved
    #  0 - not-approved
    # -1 - deleted
    add_column :operations, :state, :integer, :default => 1, :null => false
  end

  def self.down
    drop_table :scheduled_records
    drop_table :operations_scheduled_records

    remove_column :operations, :state
  end
end
